package com.quick.develop.business.enums;

import cn.hutool.core.exceptions.ExceptionUtil;
import com.quick.develop.business.vo.BusinessEnumVO;
import lombok.Getter;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Getter
public enum BusinessEnums {

    BUSINESS_TYPE_ADD("dynamicForm", "dynamicForm", "动态表单");

    private final String businessType;
    private final String businessName;
    private final String businessDesc;

    BusinessEnums(String businessType, String businessName, String businessDesc) {
        this.businessType = businessType;
        this.businessName = businessName;
        this.businessDesc = businessDesc;
    }

    public static BusinessEnums getBusinessEnums(String businessType) {
        for (BusinessEnums businessEnums : BusinessEnums.values()) {
            if (businessEnums.getBusinessType().equals(businessType)) {
                return businessEnums;
            }
        }
        return null;
    }

    public static String getDefinitionBeanName(String businessType) {
        BusinessEnums businessEnums = getBusinessEnums(businessType);
        if (businessEnums != null) {
            return businessEnums.getBusinessName();
        }
        throw ExceptionUtil.wrapRuntime("获取业务类型失败！");
    }


    public static List<BusinessEnumVO> getBusinessEnumsList() {
       return Arrays.stream(BusinessEnums.values())
               .map(e-> new BusinessEnumVO(e.getBusinessType(), e.getBusinessDesc(),e.getBusinessName()))
               .collect(Collectors.toList());
    }
}
